
import 'package:favourcate/core/router/router.dart';
import 'package:favourcate/core/viewmodel/filter_view_model.dart';
import 'package:favourcate/core/viewmodel/meal_view_model.dart';
import 'package:favourcate/core/viewmodel/favor_view_model.dart';
import 'package:favourcate/ui/shared/app_theme.dart';
import 'package:favourcate/ui/shared/screen_fit.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

void main() {
  // runApp(ChangeNotifierProvider(
  //   create: (ctx) => MealViewModel(),
  //   child: const MyApp(),
  // ));

  runApp(
    MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (ctx) => GLFilterViewModel(),),
        // ChangeNotifierProvider(create: (ctx) => MealViewModel(),),
        ChangeNotifierProxyProvider<GLFilterViewModel, MealViewModel>(
          create: (ctx) => MealViewModel(),
          update: (ctx, filterStore, mealStore) {
            mealStore!.updateFilters(filterStore);
            return mealStore;
          }
        ),
        // ChangeNotifierProvider(create: (ctx) => GLFavorViewModel()),
        ChangeNotifierProxyProvider<GLFilterViewModel, GLFavorViewModel>(
          create: (ctx) => GLFavorViewModel(),
          update: (ctx, filterStore, favorMealStore) {
            favorMealStore!.updateFilters(filterStore);
            return favorMealStore;
          }
        ),
      ],
      child: const MyApp(),
    )
  );
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // 初始化适配
    GLScreenFit.initilize();
    return MaterialApp(
      title: '美食广场',
      theme: AppTheme.norTheme(context),
      initialRoute: GLRouter.initialRoute,
      routes: GLRouter.routes,
      onGenerateRoute: GLRouter.generateRoute,
      onUnknownRoute: GLRouter.unknownRoute,
      // home: GLMainScreen()
    );
  }
}



///  http://123.207.32.32:8001/api/meal 接口
/// http://123.207.32.32:8001/api/category